<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Coupon_info_model extends Base_Model{
	var $page_size = 10;
	public function __construct() {
		$this->db_tablepre = 't_sys_';
		$this->table_name = 'coupon_info';
		parent::__construct();
	}
	public function listinfos($where = '',$data='*', $order = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array()){
		$sql = "SELECT ".$data."
				from t_sys_coupon_info cin LEFT JOIN t_sys_coupon c on (c.id=cin.couponid)
				LEFT JOIN t_sys_users u on (cin.userid=u.id)
				where cin.delete_flag = 0".$where."
						order by cin.id desc";
		//$this->number = $this->count($where1);
		$this->number =  count($this->select_sql($sql));
		$page = max(intval($page), 1);
		$offset = $pagesize*($page-1);
		if($offset>$this->number)
		{
			$page=round($this->number/$pagesize);
			$offset = max($pagesize*($page-1),0);
		}
		if($this->number >$pagesize)
			$this->pages = pages($this->number, $page, $pagesize, $urlrule, $array, $setpages);
			else
				$this->pages = "";
				$array = array();
				if ($this->number > 0) {
					$sql.= " limit ".$offset.",".$pagesize;
				return $this->select_sql($sql);
				} else {
					return array();
				}
	}
}
